package cn.edu.scau.cmi.liujianxun.client.fxUI.mutipleton;

import cn.edu.scau.cmi.liujianxun.singleton.Marshal;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

public class MultipletonDemoController {
	@FXML
	private TextArea text;
	@FXML
	private Button bt1;
	@FXML
	private Button bt2;

	String[] marshalList = {"朱德", "彭德怀", "林彪", "刘伯承", "贺龙", "陈毅", "罗荣桓", "徐向前", "聂荣臻", "叶剑英"};
	
	public MultipletonDemoController() {
		
	}
	
	public void bt1Event() {
		int num = Marshal.size();
		if(num == 10) {
			text.appendText("添加失败，元帅已满10个，元帅名单为:：\n");
			for (Marshal m : Marshal.getMarshalSet()) {  
				text.appendText(m.getName() + "\n");
			}
		}
		else if(Marshal.getInstance(marshalList[num]) != null) {
			text.appendText("创建成功，添加的元帅名字为" + marshalList[num] + "\n");
		}
	}
	
	public void bt2Event() {
		if(Marshal.size() == 0)
			text.appendText("尚未创建元帅\n");
		else {
			text.appendText("元帅名单为:：\n");
			for (Marshal m : Marshal.getMarshalSet()) {  
				text.appendText(m.getName() + "\n");
			}
		}
	}
}
